<?php
declare (strict_types=1);

namespace app\user\model\user;

use app\common\model\BaseModel;
use app\course\logic\base\Course;
use think\model\relation\BelongsTo;

/**
 * 定义用户分成模型
 */
class SplitCourse extends BaseModel
{
    /**
     * 表名
     *
     * @var string
     */
    protected $name = 'user_split_course';

    /**
     * 设置自动写入时间
     *
     * @var boolean
     */
    protected $autoWriteTimestamp = true;

    /**
     * 定义字段类型
     *
     * @var array
     */
    protected $type = [
        'id'                     => 'integer',
        'order_no'               => 'string',
        'user_id'                => 'integer',
        'course_id'              => 'integer',
        'section_id'             => 'integer',
        'mhm_id'                 => 'integer',
        'payment'                => 'float',
        'platform_sum'           => 'float',
        'school_user_id'         => 'integer',
        'school_sum'             => 'float',
        'teacher_id'             => 'integer',
        'teacher_sum'            => 'float',
        'mount_id'               => 'integer',
        'mount_sum'              => 'float',
        'share_user_id'          => 'integer',
        'share_user_sum'         => 'float',
        'share_exchange'         => 'integer',
        'primary_user_id'        => 'integer',
        'primary_distribution'   => 'float',
        'secondary_user_id'      => 'integer',
        'secondary_distribution' => 'float',
        'status'                 => 'integer',
        'note'                   => 'string',
        'create_time'            => 'integer',
        'update_time'            => 'integer',
        'delete_time'            => 'integer',
    ];

    /**
     * 定义表主键
     *
     * @var string
     */
    protected $pk = 'id';

    /**
     * 关联课程封面
     * Author 亓官雨树<lucky.max@foxmail.com>
     * Date 2021-06-24
     *
     * @return BelongsTo [type] [description]
     */
    public function courseCover()
    {
        return $this->belongsTo(Course::class, 'course_id')->with(['cover_url'])->bind(['cover_url']);
    }

    /**
     * 关联课程封面
     * Author 亓官雨树<lucky.max@foxmail.com>
     * Date 2021-06-24
     *
     * @return BelongsTo [type] [description]
     */
    public function courseTypeText()
    {
        return $this->belongsTo(Course::class, 'course_id')->append(['course_type_text'])->bind(['course_type_text']);
    }
}
